﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;
using MediaBrowserSL.RIA.ViewModels;
using MediaBrowserSL.RIA.Views;

namespace MediaBrowserSL.RIA.Converters
{
    /// <summary>
    /// Convert ViewModel to View
    /// </summary>
    public class ViewModelViewConverter : IValueConverter
    {
        Dictionary<PageViewModelBase, UserControl> vm_view = new Dictionary<PageViewModelBase, UserControl>();

        public ViewModelViewConverter()
        {
            vm_view = new Dictionary<PageViewModelBase, UserControl>();
            Locator l = (Locator)App.Current.Resources["Locator"];
            vm_view.Add(l.Home, new PageHomeView());
            vm_view.Add(l.Movies, new PageMoviesView());
            vm_view.Add(l.Pictures, new PagePicturesView());
            vm_view.Add(l.Books, new PageBooksView());
            vm_view.Add(l.Musics, new PageMusicView());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            PageViewModelBase vm = value as PageViewModelBase;
            try
            {
                return vm_view[vm];
            }
            catch (Exception)
            {
                return null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

    }
}
